﻿<!DOCTYPE html>
<!--菜单管理-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .upload-demo {
            margin-left: 0px;
        }
    </style>
</head>

<body>

    <div id="app" v-cloak>
        <el-row>
            <el-col :span="24">
                <el-form label-position="right" ref="form" :inline="true" :model="formInline" class="demo-form-inline"
                         style="margin-bottom: 15px;">
                    <el-row>
                        <el-col class="head-tool">
                            <div class="new_title fl">
                                <strong><img src="/static/images/icon1.png" />功能管理列表</strong>
                            </div>
                            <span>
                                <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="3"
                                     @click="onSubmit">
                                </btn>
                                <btn :text="col.btnAdd" linetype="3" v-if="authorize('MenuController_SaveAsync')"
                                     @click="UserInput('tj')"></btn>
                             
                                <btn :text="col.btnDelete" @click="onDelete"></btn>

                            </span>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.Name" :placeholder="SysMenu.Name" size="mini">
                                        <template slot="prepend">
                                            {{SysMenu.Name+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.Code" :placeholder="SysMenu.Code" size="mini">
                                        <template slot="prepend">
                                            {{SysMenu.Code+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input size="mini">
                                        <template slot="prepend">
                                            {{SysMenu.Type+mark.m}}
                                        </template>
                                        <el-select @visible-change="visibleChange" v-model="formInline.model.Type" slot="suffix"
                                                   :placeholder="SysMenu.Type">
                                            <el-option label="请选择" value=""></el-option>
                                            <el-option label="菜单" value="0"></el-option>
                                            <el-option label="功能" value="1"></el-option>
                                        </el-select>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>

                </el-form>
                 <!-- 解决表格展开不出滚动条bug 加类 ele_expand  -->
                <el-table class="ele_expand" ref="table" :data="ListItem.tableData" :height="ListItem.tableHeight" border
                          :tree-props="{children: 'children', hasChildren: 'hasChildren'}" highlight-current-row
                          row-style="height:10px" row-key="id" @selection-change="handleSelectionChange"
                          @row-click="tableRowClick" style="width: 100%">
                    <el-table-column type="selection" align="center" width="55">
                    </el-table-column>

                    <el-table-column type="index" :label="SysMenu.No" :index="indexMethod" width="50"
                                     show-overflow-tooltip="true">

                    </el-table-column>
                    <el-table-column prop="name" :label="SysMenu.Name" align="left" show-overflow-tooltip="true" min-width="200">
                    </el-table-column>
                    <el-table-column prop="code" :label="SysMenu.Code" min-width="200" show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="url" :label="SysMenu.Url" min-width="300" show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="type" :label="SysMenu.Type" min-width="50" show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{scope.row.type==0?'菜单':'功能'}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="remarks" :label="SysMenu.Remarks" min-width="50" show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column width="53" v-if="authorize('MenuController_SaveAsync')" prop="update"
                                     :label="col.btnUpdate" fixed="right">
                        <template slot-scope="scope">
                            <button type="button" class="elst-bt-xg" @click=UserInput('xg',scope.row.id)>
                                <i class="el-icon-edit"></i>
                            </button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <el-dialog title="菜单管理" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="100%"
                   top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:320%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    pageInitial: {},
                    //页面内数据初始化
                    ListItem: ListItem,
                    formInline: {
                        model: {
                        },
                    },
                    Types: [],
                    currSeelctId: null
                }
            },
            mounted: function () {
                this.pageInitial = PageInitial(null, [
                    "MenuController_GetList",
                    "MenuController_SaveAsync",
                    "MenuController_DeleteMutiAsync",
                    "MenuController_Get"
                ]);
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);
                this.Types = [];
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                authorize: function (functionCode) { return authorize(this.pageInitial.authorizeList, functionCode); },
                //表格序号连续化
                indexMethod: function (index) {
                    return index + 1;
                },
                closeDialog: function () { closeDialog(this); },
                //删除方法
                onDelete: function () {
                    var mythis = this;
                    if (mythis.ListItem.tableMultipleSelection.length == 0) {
                        showMessage(msg.AtLeastOne, 'error')
                        return;
                    }
                    mythis.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        var delIds = [];
                        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
                            var item = mythis.ListItem.tableMultipleSelection[i];
                            delIds.push(item.id);
                        }
                        myAjax("post", mythis, '/api/Menu/DeleteMuti', delIds, function (response) {
                            mythis.GetPageData(1);
                            showMessage(msg.OperatingOk, "success");
                        });
                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) {


                    var urlParam = "_t=" + Date.parse(new Date());
                    if (this.currSeelctId)
                        urlParam = "menuId=" + this.currSeelctId + "&" + urlParam;
                    DialogShow(this, val, "SysMenuInput.html", id, urlParam);
                },
                //获取分页数据
                GetPageData: function (currentIndex) {
                    var mythis = this;
                    myAjax("post", this, '/api/Menu/GetList', this.formInline, function (response) {
                        var data = MenuHelper(response.data, "");
                        this.ListItem.tableData = data;
                    });
                    //重置当前选择ID
                    this.currSeelctId = null;
                },
                //查询方法
                onSubmit: function () { onSubmit(this); },
                //点击行事件
                tableRowClick: function (currentRow) {
                    if (currentRow.id == this.currSeelctId) {
                        this.$refs.table.setCurrentRow(null);
                        this.currSeelctId = null;
                    }
                    else
                        this.currSeelctId = currentRow.id;
                }
            }
        });
        //数据序列化(tabletree)
        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (v.parentId == pid) {
                    var obj = {};
                    for (var key in v) {
                        obj[key] = v[key];
                    }
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>